package com.mapull.clone;

/**
 * @author mapull
 */
public class MapullClone {

    public static void main(String[] args) {
//        simpleClone();
        referClone();
    }

    private static void simpleClone(){
        Student first = new Student();
        first.setAge(6);
        first.setName("Tom");

        System.out.println("First student " + first);

        Student second = first.clone();

        System.out.println("Second student " + second);

        // 修改原始对象内容
        first.setName("Jerry");

        System.out.println("First student " + first);
        System.out.println("Second student " + second);
    }

    private static void referClone(){
        Address address = new Address();
        address.setCode("10101");
        address.setHouseNumber("2号楼302");
        Student first = new Student();
        first.setAge(6);
        first.setName("Tom");
        first.setAddress(address);


        System.out.println("First student " + first);

        Student second = first.clone();

        System.out.println("Second student " + second);

        // 修改原始对象内容
        first.getAddress().setHouseNumber("5号楼101");

        System.out.println("First student " + first);
        System.out.println("Second student " + second);
    }


}
